#include <wx/htmllbox.h>
#include "wxssimplehtmllistbox.h"

namespace {
  wxsRegisterItem<wxsSimpleHtmlListBox> Reg( _T( "SimpleHtmlListBox" ), _T( "简单Html列表框" ), wxsTWidget, _T( "标准" ), 120 );
  WXS_ST_BEGIN( wxsSimpleHtmlListBoxStyles, wxT( "wxHLB_DEFAULT_STYLE" ) )
  WXS_ST_CATEGORY( "wxSimpleHtmlListBox" )
  WXS_ST( wxHLB_DEFAULT_STYLE )
  WXS_ST( wxHLB_MULTIPLE )
  WXS_ST( wxLB_EXTENDED )
  WXS_ST( wxLB_HSCROLL )
  WXS_ST_DEFAULTS()
  WXS_ST_END()
  WXS_EV_BEGIN( wxsSimpleHtmlListBoxEvents )
  WXS_EVI( EVT_LISTBOX, wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEvent, Select )
  WXS_EVI( EVT_LISTBOX_DCLICK, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEvent, DClick )
  WXS_EVI( EVT_HTML_CELL_CLICKED, wxEVT_COMMAND_HTML_CELL_CLICKED, wxHtmlCellEvent, CellClicked )
  WXS_EVI( EVT_HTML_CELL_HOVER, wxEVT_COMMAND_HTML_CELL_HOVER, wxHtmlCellEvent, CellHover )
  WXS_EVI( EVT_HTML_LINK_CLICKED, wxEVT_COMMAND_HTML_LINK_CLICKED, wxHtmlLinkEvent, LinkClicked )
  WXS_EV_END()
}

wxsSimpleHtmlListBox::wxsSimpleHtmlListBox( wxsItemResData *Data ):
  wxsWidget(
    Data,
    &Reg.Info,
    wxsSimpleHtmlListBoxEvents,
    wxsSimpleHtmlListBoxStyles ),
  DefaultSelection( -1 ) {
}

void wxsSimpleHtmlListBox::OnBuildCreatingCode() {
  switch( GetLanguage() ) {
    case wxsCPP: {
      AddHeader( _T( "<wx/htmllbox.h>" ), GetInfo().ClassName, hfInPCH );
      Codef( _T( "%C(%W, %I, %P, %S, 0, 0, %T, %V, %N);\n" ) );
      for( size_t i = 0; i <  ArrayChoices.GetCount(); ++i ) {
        if( DefaultSelection == ( int )i ) {
          Codef( _T( "%ASetSelection( " ) );
        }
        Codef( _T( "%AAppend(%t)" ), ArrayChoices[i].wx_str() );
        if( DefaultSelection == ( int )i ) {
          Codef( _T( " )" ) );
        }
        Codef( _T( ";\n" ) );
      }
      BuildSetupWindowCode();
      return;
    }
    case wxsUnknownLanguage:
    default: {
      wxsCodeMarks::Unknown( _T( "wxsSimpleHtmlListBox::OnBuildCreatingCode" ), GetLanguage() );
    }
  }
}


wxObject *wxsSimpleHtmlListBox::OnBuildPreview( wxWindow *Parent, long Flags ) {
  wxSimpleHtmlListBox *Preview = new wxSimpleHtmlListBox( Parent, GetId(), Pos( Parent ), Size( Parent ), 0, 0, Style() );
  for( size_t i = 0; i <  ArrayChoices.GetCount(); ++i ) {
    int Val = Preview->Append( ArrayChoices[i] );
    if( ( int )i == DefaultSelection ) {
      Preview->SetSelection( Val );
    }
  }
  return SetupWindow( Preview, Flags );
}


void wxsSimpleHtmlListBox::OnEnumWidgetProperties( M_Code_unused long Flags ) {
  WXS_ARRAYSTRING( wxsSimpleHtmlListBox, ArrayChoices, _T( "Choices" ), _T( "content" ), _T( "item" ) )
  WXS_LONG( wxsSimpleHtmlListBox, DefaultSelection, _T( "Default" ), _T( "default" ), 0 )
}
